package cn.deali.homework9.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cn.deali.homework9.R;
import cn.deali.homework9.adapter.LocalMusicAdapter;
import cn.deali.homework9.model.LocalMusic;
import cn.deali.homework9.utils.LocalMusicUtils;

public class LocalMusicFragment extends Fragment {
    private Context mContext;

//    public LocalMusicFragment(Context context) {
//        mContext = context;
//    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View returnView = inflater.inflate(R.layout.fragment_local_music, container, false);

        List<LocalMusic> localMusics = LocalMusicUtils.getmusic(getContext());
//        Toast.makeText(mContext, "localMusic" + localMusics.size(), Toast.LENGTH_SHORT).show();

        RecyclerView recyclerView = returnView.findViewById(R.id.localMusicList);
        LocalMusicAdapter localMusicAdapter = new LocalMusicAdapter(getContext(), localMusics);
        recyclerView.setAdapter(localMusicAdapter);

        //设置layout manager，默认垂直分布
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
        recyclerView.setLayoutManager(linearLayoutManager);

        return returnView;
    }
}
